<?php
/*
    内容：发货提示相关操作（添加、删除）
    时间：2017.4.7
    zeng
*/
class b2c_ctl_admin_goods_tips extends desktop_controller
{
	function index(){
        $custom_actions[] = array(
                'label'=>app::get('b2c')->_('添加发货提示'),
                'icon'=>'add.gif',
                'href'=>'index.php?app=b2c&ctl=admin_goods_tips&act=add',
                'target'=>'dialog::{ title:\''.app::get('b2c')->_('添加发货设定规则').'\', width:1000, height:500}'
            );
        $custom_actions[]=array(
                'label'=>app::get('b2c')->_('删除'),
                'submit'=>'index.php?app=b2c&ctl=admin_goods_tips&act=remove',
            );
          $actions_base['actions'] = $custom_actions;
          $actions_base['title']=app::get('b2c')->_('发货提示设定管理');
          $actions_base['use_buildin_recycle'] = false;//关闭系统删除功能，自己设计删除功能
          $actions_base['use_buildin_filter'] = false;
//        $actions_base['use_buildin_export'] = true;
          $actions_base['allow_detail_popup'] = true;
//        $actions_base['use_view_tab'] = true;

          $this->finder('b2c_mdl_tips',$actions_base);
    }
	
    //添加修改商品发货提示设定
	function add()
	{
		$tip_id = $_GET['p'][0];//发货提示号
        if($tip_id){
            $arrTips = app::get('b2c')->model('goods_tips')->getList('*',array('gnotify_id'=>$tip_id));
            $tips = $arrTips[0];
            $tips['value'] = unserialize($tips['value']);//解序列化
            $tips['count']=count($tips['value']);//统计该商品发货提示数量，用于在前台edit_goodstips.html的js代码中id，此处为了解决Bug
            $this->pagedata['tips'] = $tips;
            $this->page('admin/goods/detail/edit_goodstips.html');//修改页面
        }else{
            $tips = array('values'=>array(0));//默认有一个
            $this->pagedata['tips'] = $tips;
            $this->page('admin/goods/detail/goodstips.html');//添加页面
        }
        
	}
    //编辑某个商品发货提示
    function editSave()
    {
        $this->begin('index.php?app=b2c&ctl=admin_goods_tips&act=index');
        $tips_id=$_POST['tips_id'];//发货提示号
        $saveData=$_POST['value'];//发货提示数据
        $edit_goods_tips_model=app::get('b2c')->model('goods_tips');
        $flag=$edit_goods_tips_model->update(array('value'=>$saveData),array('gnotify_id'=>$tips_id));
        if($flag)
            $this->end(true,app::get('b2c')->_('操作成功'));
        else
            $this->end(false,app::get('b2c')->_('操作失败'));
    }

    //添加发货提示
    function mysave()
    {
        $this->begin('index.php?app=b2c&ctl=admin_goods_tips&act=index');
        $linkid_arr=$_POST['linkid'];//发货提示商品ID数组
        $tips_arr_value=serialize($_POST['values']);//发货提示内容序列化

        //需要的Model,进行数据库操作
        $goods_tips_model=app::get('b2c')->model('goods_tips');
        $product_model= app::get('b2c')->model('products');

        //获取货号、商品号、商品名称
        $product_info_arr=$product_model->getList('product_id,goods_id,name', array('goods_id'=>$linkid_arr));

        foreach($product_info_arr as $key => $value)
        {
            $data[$key]['product_id']=$value['product_id'];
            $data[$key]['goods_id']=$value['goods_id'];
            $data[$key]['name']=$value['name'];
            $data[$key]['value']=$tips_arr_value;            
        }
        //循环插入数据
        foreach ($data as $key => $value) 
        {
            $flag=$goods_tips_model->save($value);
        }
        if($flag)
            $this->end(true,app::get('b2c')->_('操作成功'));
        else
            $this->end(false,app::get('b2c')->_('列表已存在商品,不能重复添加'));
        
    }

    //删除发货提示
    function remove()
    {
         $this->begin('index.php?app=b2c&ctl=admin_goods_tips&act=index');
         $gnotify_id_arr=$_POST;//发货提示ID
         $goods_tips_model=app::get('b2c')->model('goods_tips');
         $this->end($goods_tips_model->delete($gnotify_id_arr),app::get('b2c')->_('选项删除成功'));//执行删除操作
    }

   
    
}


?>